package lanqiaobeiGuosai.dfs;

import java.util.Scanner;

public class 路径之谜 {
    //标记为上下左右
    static int[] direction_x = {-1,1,0,0};
    static int[] direction_y = {0,0,-1,1};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int N = scan.nextInt();
        int[][] arr = new int[2][N];
        for (int i = 0; i < arr.length; i++) {
            for (int i1 = 0; i1 < N; i1++) {
                int x = scan.nextInt();
                arr[i][i1] = x;
            }
        }
        //使用Boolean数组设置对应的路径是否走过
        boolean[][] map = new boolean[N][N];
        //最后的结果一定是唯一的，那么只需要记录一个即可
        StringBuilder stringBuilder = new StringBuilder();
        //DFS搜索详细信息
        //backTracking();

        scan.close();
    }
    public static void backTracking(String str, boolean[][] map,int now_x, int now_y,int[][] rowAndColFlag) {
        //不满足情况
        if (now_x<0 || now_y<0 || now_y > map.length-1 || now_x > map[0].length-1) return;
        //向四个方向搜索
        int x_x = now_x;
        int y_y = now_y;

        int[] rows = rowAndColFlag[0];
        int[] cols = rowAndColFlag[1];


        //上方
        x_x = now_x-1;
        if (x_x >=0 && !map[x_x][now_y] && rows[y_y] - 1>=0) {
            //满足情况 添加
            //标记已经走过
            map[x_x][now_y] = true;
            backTracking(str+(now_x*map.length + now_y), map, x_x, y_y,rowAndColFlag);
            map[x_x][now_y] = false;
        }

        //下方
        x_x = now_x + 1;
        if (x_x < map.length && !map[x_x][now_y] && rows[y_y] - 1 >= 0) {
            //满足情况 添加
            //标记已经走过
            map[x_x][now_y] = true;
            backTracking(str+(now_x*map.length + now_y), map, x_x, y_y,rowAndColFlag);
            map[x_x][now_y] = false;
        }

        //左方
        y_y = now_y - 1;
        if (y_y >=0 && !map[now_x][y_y] && rows[x_x] - 1 >= 0) {
            //满足情况 添加
            //标记已经走过
            map[now_x][y_y] = true;
            backTracking(str+(now_x*map.length + now_y), map, x_x, y_y,rowAndColFlag);
            map[now_x][y_y] = false;
        }

        //右方
        y_y = now_y + 1;
        if (y_y >=0 && !map[now_x][y_y] && rows[x_x] - 1 >= 0) {
            //满足情况 添加
            //标记已经走过
            map[now_x][y_y] = true;
            backTracking(str+(now_x*map.length + now_y), map, x_x, y_y,rowAndColFlag);
            map[now_x][y_y] = false;
        }
    }
}
